<?php
// View for admin - scrolling news
require_once WACT_ROOT.'controller/controller.inc.php';
require_once WACT_ROOT .'controller/form.inc.php';
require_once WACT_ROOT.'view/view.inc.php';
require_once WACT_ROOT .'view/formview.inc.php';

require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';

require_once 'model/common/user.php';
require_once 'model/common/scrolling.php';
require_once 'model/common/categories.php';
require_once 'model/common/date.php';


class ScrollingListView extends LayoutFormView {

    function ScrollingListView($TemplateFile) {
        parent :: LayoutFormView($TemplateFile);
    }

    function prepare(&$controller, &$request, &$responseModel) {
    	parent::prepare($controller, $request, $responseModel);
		        
		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
 

		$pager =& $this->Template->getChild('pagenav');
        $pager2 =& $this->Template->getChild('pagenav2');
        $list =& Scrolling::getScrollingList($pager,$request);
        $list->paginate($pager2);


        $list_updated=array();


        $list->reset();
        while ($list->next()) {

        	$dataspace = $list->export();
            $firstname = $list->get('firstname');
            $lastname = $list->get('lastname');
            $id = $list->get('id');
            $author_show = $firstname.' '.$lastname;
            $dataspace['author_show'] =  $author_show;

            $category1 = $list->get('category1');
            $category2 = $list->get('category2');

            $category_show = $category1.'-'.$category2;
            $dataspace['category_show'] =  $category_show;

            // determine whether enabled or disabled
            $enabled = $list->get('enabled');
            $expiration_date = $list->get('expiration_date');

            $tz =& new MyTimeZone();


            $ts_expire = strtotime($expiration_date);
            $ts_expire = $tz->timeGMT($ts_expire);

            $ts_now = $tz->timeNowLocal();

            //$ts_now = strtotime(date("Y-m-d H:i"));
            //print $ts_now.'/'.$ts_expire.'\n';
            $status_show = ( ($ts_now < $ts_expire) && $enabled )?'enabled':'disabled';
            $dataspace['status_show'] =  $status_show;

            //print_r($dataspace);
            $list_updated[$id] = $dataspace;
        }


        $list_source_updated =& new ArrayDataSet($list_updated);
        $this->Template->setChildDataSource('List', $list_source_updated);



    }

}






?>